package com.douyu.interceptor;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.douyu.water.core.service.UserUtil;

public class AuthInterceptor extends HandlerInterceptorAdapter{

	private List<String> skip;
	private UserUtil userUtil;
	
	public UserUtil getUserUtil() {
		return userUtil;
	}

	public void setUserUtil(UserUtil userUtil) {
		this.userUtil = userUtil;
	}

	public List<String> getSkip() {
		return skip;
	}

	public void setSkip(List<String> skip) {
		this.skip = skip;
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub
		//返回处理（已经渲染了页面）
		
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object arg2, ModelAndView arg3)
			throws Exception {
		// TODO Auto-generated method stub
		//后处理（调用了Service并返回ModelAndView，但未进行页面渲染）
		
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		// TODO Auto-generated method stub
//		request.setCharacterEncoding("UTF-8");
//		response.setCharacterEncoding("UTF-8");
		//预处理
		//请求URI验证
		String uri = request.getRequestURI();
		uri = uri.replaceAll("[\\\\]+", "/");	
		if(skip.contains(uri))
		{
			//免登陆认证部分
		}
		else
		{			
			//登录认证操作			
		}
		return true;
	}
  	
}
